import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.seven332'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 10
        versionName "0.1.9"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main {
            // Disable default NdkCompile task
            jni.srcDirs = []
            // Set new jni lib dir
            jniLibs.srcDir 'src/main/libs'
        }
    }
}

clean {
    delete file('src/main/obj').absolutePath
    delete file('src/main/libs').absolutePath
}

// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
    def ndkBuilder
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        ndkBuilder = 'ndk-build.cmd'
    } else {
        ndkBuilder = 'ndk-build'
    }
    commandLine "$ndkBuilder",
            '-C', file('src/main').absolutePath,
            '-j', Runtime.runtime.availableProcessors()
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

task javah(type: Exec, dependsOn: 'compileReleaseJavaWithJavac') {
    commandLine 'javah', '-jni',
            '-d', 'javah',
            '-cp', "${android.getSdkDirectory().getAbsolutePath()}/platforms/android-23/android.jar;build/intermediates/classes/release",
            'com.hippo.image.Image'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-annotations:23.4.0'
    testCompile 'junit:junit:4.12'
}

// build a jar with source files
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    failOnError  false
    source = android.sourceSets.main.java.sourceFiles
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    classpath += configurations.compile
}

// build a jar with javadoc
task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}
